<!--
 * @Author: 莫莫
 * @Phone: 13450159681
 * @Description: 
 * @Date: 2024-08-08 15:03:49
 * @LastEditTime: 2024-08-24 14:02:04
-->
<template>
	<view class="body d-s-c d-c">
		<image src="@/static/head.png" mode="widthFix" class="ww100"></image>
		<view class="p60">
			<!-- <view class="tip sub f22 mb40">*如您是欧比内部销售人员，点击下方按钮进行注册，我们将对您的手机号进行校验，非欧比内部销售人员，不允许注册。</view> -->
			<view class="item mb20 d-b-c pl40 pr40">
				<input class="f28" type="text" placeholder="输入账号" v-model="data.account" />
			</view>
			<view class="item mb20 d-b-c pl40 pr40">
				<input class="f28" type="password" placeholder="输入密码" v-model="data.password" />
			</view>
			<view class="mb40 mt50">
				<label class="radio f24" @click="setRadio">
					<radio :checked="data.radio" color="#d2000f" /> 我已阅读<text>《用户协议》</text>与<text>《隐私政策》</text>，并同意协议内容
				</label>
			</view>
			<view class="ww100">
				<up-button :throttleTime="1000" throttleTime="1000" @click="login" shape='circle' color='#d2000f'
					text="登录"></up-button>
			</view>
		</view>
	</view>
</template>
<script setup>
	import { reactive } from 'vue'
	import { onLoad } from "@dcloudio/uni-app";
	import { useStore } from "vuex"
	const store = useStore()
	const data = reactive({
		radio: false,
		account: '',
		password: ""
	})
	async function login() {
		if (!data.radio) return store.commit('tip', '请阅读《用户协议》与《隐私政策》，并同意协议内容')
		if (data.account == '') return store.commit('tip', '请输入账号')
		if (data.password == '') return store.commit('tip', '请输入密码')
		const res = await store.dispatch('request', {
			url: store.state.api.login,
			method: "POST",
			data: {
				account: data.account,
				password: data.password
			},
		})
		if (res.code == 1) {
			store.commit('tip', '登录成功')
			uni.setStorageSync('token', res.data.userinfo.token)
			uni.setStorageSync('userinfo', res.data.userinfo)
			setTimeout(() => {
				store.commit('jump', '/pages/index/index')
			}, 1000)
		}
	}

	function setRadio() {
		data.radio = !data.radio
	}
	onLoad(() => {
		if (uni.getStorageSync('token')) {
			store.commit('jump', '/pages/index/index')
		}
	})
</script>
<style scoped lang="scss">
	.item {
		background-color: #fff;
		border-radius: 60rpx;
		height: 70rpx;
		box-shadow: 0rpx 5rpx 15rpx 0rpx rgba(210, 0, 15, .2);
	}

	.code {
		color: #d2000f;
	}

	.deCode {
		color: #999;
	}

	.body {
		background-color: #fbf7eb;

		.logo {
			width: 250rpx;
		}
	}

	.radio {
		color: #999;

		radio {
			transform: scale(0.8);
		}

		text {
			color: $uni-color-error
		}
	}
</style>